#pragma once
#include <iostream>
using namespace std;
#include <functional>
#include <unordered_map>
#include <time.h>
#include <stdlib.h>
using task_t = function<void()>;
static int number = 0;
class Channel
{
public:
    Channel(int fd,int pid)
        : _wfd(fd),_pid(pid)
    {
        _name = "Channel" + to_string(number++);
    }

    void debug()
    {
        cout << _wfd << ":" << _name << endl;
    }
    int Wfd()
    {
        return _wfd;
    }
    string Name()
    {
        return _name;
    }
    int Pid()
    {
        return _pid;
    }
private:
    int _wfd;
    string _name;
    int _pid;//子进程的pid
};






void Load()
{
    cout << "加載功能..." << endl;
}
void Update()
{
    cout << "下載功能..." << endl;
}

void Log()
{
    cout << "日誌功能..." << endl;
}
static int num = 1;
class Task
{
public:
    Task()
    {
        srand((unsigned int)time(nullptr));
        Insert(function<void()>(Load));
        Insert(function<void()>(Update));
        Insert(function<void()>(Log));
    }
    void Insert(task_t t)
    {
        task[num++] = t;
    }
    int Select()
    {
        int n = rand()%num;
        return n;
    }
    task_t FindWork(int n)
    {
        // if(!task.count(n))
        //     return task_t(nullptr);
        return task[n];
    }
private:
    unordered_map<int, task_t> task;
};


Task t;